package com.lagou.edu.controller;

import com.lagou.edu.pojo.Resume;
import com.lagou.edu.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;


@Controller
@RequestMapping("/Resume")
public class ResumeController {
    @Autowired
    private ResumeService resumeService;

    @RequestMapping("/queryAll")
    @ResponseBody
    public List<Resume> queryAll(){
      return resumeService.queryAllResume();
    }


    @RequestMapping("/add")
    public ModelAndView addResume(String name,String address,String phone){
        ModelAndView modelAndView = new ModelAndView();
        Resume resume = new Resume();
        resume.setName(name);
        resume.setAddress(address);
        resume.setPhone(phone);
        resumeService.update(resume);
        modelAndView.setViewName("redirect:/list");
        return modelAndView;
    }

    @RequestMapping("/update")
    public ModelAndView updateResume(Long id,String name,String address,String phone){
        ModelAndView modelAndView = new ModelAndView();
        Resume resume = new Resume();
        resume.setId(id);
        resume.setName(name);
        resume.setAddress(address);
        resume.setPhone(phone);
        resumeService.update(resume);
        modelAndView.setViewName("redirect:/list");
        return modelAndView;
    }



    @RequestMapping("/delete")
        public String updateResume(long id){
            boolean result = resumeService.deleteResume(id);
            if(!result){
            return "forward:/error.jsp";
        }
        return "redirect:/list";
    }
}
